//
//  HotelDetailsViewController.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/7/1.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "HotelDetailsViewController.h"
#import "HotelDetailsViewControllerCollectionViewCell.h"
#import "MovieCommentTableViewCell.h"
#import "TLDisplayView.h"

static NSString * tableViewIndentifer = @"MovieCommentTableViewCell";
static NSString * collectionViewIndentifer = @"HotelDetailsViewControllerCollectionViewCell";

@interface HotelDetailsViewController ()
<UICollectionViewDataSource,UICollectionViewDelegate,UITableViewDelegate,UITableViewDataSource,TLDisplayViewDelegate>

@property (strong, nonatomic) IBOutlet UIScrollView *scroview;
@property (strong, nonatomic) IBOutlet UICollectionView *collectView;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) TLDisplayView *displayView;
@property (weak, nonatomic) IBOutlet UIView *bottomView;

@end

@implementation HotelDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initViewLayout];
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.scroview];
    [self adaptiveViewLayout:self.bottomView];

    _scroview.contentSize = flexibleSize(CGSizeMake(0, 740), NO);
    
    
    UICollectionViewFlowLayout *FlowLayout =[[UICollectionViewFlowLayout alloc]init];
    FlowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    FlowLayout.minimumInteritemSpacing = 0*VerticalRatio();
    FlowLayout.minimumLineSpacing = 0*VerticalRatio();
    self.collectView.collectionViewLayout = FlowLayout;
    
    [self.collectView registerNib:[UINib nibWithNibName:collectionViewIndentifer bundle:nil] forCellWithReuseIdentifier:collectionViewIndentifer];
    self.collectView.backgroundColor = [UIColor whiteColor];
    self.collectView.showsVerticalScrollIndicator = NO;
    self.collectView.delegate = self;
    self.collectView.dataSource = self;
    
    [self.tableView registerNib:[UINib nibWithNibName:tableViewIndentifer bundle:nil] forCellReuseIdentifier:tableViewIndentifer];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    
    _displayView = [[TLDisplayView alloc] init];
    _displayView.delegate = self;
    _displayView.backgroundColor = [UIColor whiteColor];
    _displayView.numberOfLines = 6;
    _displayView.font = [UIFont systemFontOfSize:14*VerticalTexeRatio()];
    _displayView.textColor = kGetColor(102, 102, 102);
    [_displayView setText:@"以商务客人而非旅游度假为主的酒店，一般认为商务客人的比例应该不低于70%。以商务客人而非旅游度假为主的酒店，一般认为商务客人的比例应该不低于70%。以商务客人而非旅游度假为主的酒店，一般认为商务客人的比例应该不低于70%。以商务客人而非旅游度假为主的酒店以商务客人而非旅游度假为主的酒店，一般认为商务客人的比例应该不低于70%。以商务客人而非旅游度假为主的酒店，一般认为商务客人的比例应该不低于70%。"];
    _displayView.openImage = @"HotelDetails17";
    _displayView.closeImage = @"HotelDetails18";
    [_displayView setOpenString:@" 更多" closeString:@" 收起" font:[UIFont systemFontOfSize:14*VerticalTexeRatio()] textColor:kGetColor(255, 165, 9)];
    
    CGSize size = [_displayView sizeThatFits:flexibleSize(CGSizeMake(303, MAXFLOAT), NO)];
    _displayView.frame = flexibleFrame(CGRectMake(7, 345, 306, size.height/VerticalRatio()), NO);
    [self.scroview addSubview:_displayView];

    
}

#pragma mark -
#pragma mark TLDisplayViewDelegate
- (void)displayView:(TLDisplayView *)label closeHeight:(CGFloat)height {
    CGRect frame = _displayView.frame;
    frame.size.height = height;
    self.displayView.frame = frame;
    _bottomView.frame = CGRectMake(0, CGRectGetMaxY(_displayView.frame)+4, 320*VerticalRatio(), CGRectGetHeight(_bottomView.frame));
    _scroview.contentSize = CGSizeMake(0, CGRectGetMaxY(_bottomView.frame)+1);
}

- (void)displayView:(TLDisplayView *)label openHeight:(CGFloat)height {
    CGRect frame = _displayView.frame;
    frame.size.height = height;
    self.displayView.frame = frame;
    _bottomView.frame = CGRectMake(0, CGRectGetMaxY(_displayView.frame)+4, 320*VerticalRatio(), CGRectGetHeight(_bottomView.frame));
    _scroview.contentSize = CGSizeMake(0, CGRectGetMaxY(_bottomView.frame)+1);
}


#pragma mark - <UICollectionViewDelegate && UICollectionViewDataSource>
//定义 UICollectionView 的 cell 个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 7;
}

//定义UICollectionView Cell的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(63*VerticalRatio(), 45*VerticalRatio());
}

//定义 UICollectionView 的边距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0);
}


//定义 UICollectionView cell 展示的内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HotelDetailsViewControllerCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionViewIndentifer forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    cell.image.image = [UIImage imageNamed:[NSString stringWithFormat:@"HotelDetails%d",indexPath.row+9]];
    
    NSArray *labelArray = [NSArray array];
    labelArray = @[@"无线上网",@"有线上网",@"停车场",@"行李寄存",@"热水洗浴",@"洗漱用品",@"刷卡消费"];
    cell.label.text = labelArray[indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
}

#pragma mark - <UITableViewDelegate && UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 107*VerticalRatio();
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MovieCommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableViewIndentifer ];
    if (cell== nil) {
        cell = [[MovieCommentTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableViewIndentifer];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
//    for (UIView *view in cell.subviews) {
//        if ([view isKindOfClass:[UILabel class]] ||[view isKindOfClass:[UIImageView class]]||[view isKindOfClass:[UIScrollView class]]||[view isKindOfClass:[UIButton class]]) {
//            [view removeFromSuperview];
//        }
//    }
//    
    
    
//    NSDictionary * dic = _commitArray[indexPath.row];
//    NSString * image = dic[@"memberImg"];
//    if (image) {
//        [cell.headImage sd_setImageWithURL:[NSURL URLWithString:image]];
//    }else{
//        cell.headImage.image = [UIImage imageNamed:@"comment1"];
//    }
//    
//    CGFloat star = [[NSString stringWithFormat:@"@%.1f",[dic[@"mgcoCommentStars"]floatValue ]]floatValue];
//    
//    CommitStarsView * stars = [[CommitStarsView alloc]initWithFrame:flexibleFrame(CGRectMake(13, 50, 80, 15), NO) Stars:star];
//    [cell addSubview:stars];
//    
//    cell.commentInfo.frame = flexibleFrame(CGRectMake(10, 72, 300, 15), YES);
//    cell.commentInfo.numberOfLines = 0;
//    cell.commentInfo.text = dic[@"mgcoContent"];
//    [cell.commentInfo sizeToFit];
//    
//    cell.name.text = dic[@"mgcoAuthor"];
//    
//    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//    [formatter setDateStyle:NSDateFormatterMediumStyle];
//    [formatter setTimeStyle:NSDateFormatterShortStyle];
//    [formatter setDateFormat:@"yyyy-MM-dd HH:MM:ss"];
//    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[dic[@"commentDate"] integerValue]/1000];
//    cell.date.text = [formatter stringFromDate:confromTimesp];
    
    
    return cell;
    

}

- (IBAction)back:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
